@include('admin.header')
<title>添加产品分类</title>
</head>
<body>
<div class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-cat-add">
	<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				父栏目：</label>
			<div class="formControls col-xs-6 col-sm-6">
<select id="pid" name="pid">

<option value="0" selected >顶级栏目</option>
@foreach($cat as $val)
		<option value="{{$val->id}}">
		<?php echo str_repeat('|---',$val->lev) ?>{{ $val->cat_name }}
		</option>
@endforeach

</select>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				栏目名称：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="catName" name="catName">
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
@include('admin.footer')

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	
	$("#form-cat-add").validate({
		/*rules:{
			catName:{
				required:true,
				minlength:4,
				maxlength:16
			},
	
		},*/
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
		 //AJAX请求设置头部
        $.ajaxSetup({
         headers: { 'X-CSRF-Token' : $('meta[name=_token]').attr('content') }
        });


        var name = $("#catName").val();
        var pid = $("#pid").val();

   /*   document.write(name);
        return;*/
			$(form).ajaxSubmit({
				type: 'post',
				url:"{{url('/admin/catadd')}}",
				data:{
					'name':name,
					'pid':pid
				},


				//什么意思????/
				//contentType: false,
                //processData: false,
				success: function(data){
					
						layer.msg('添加成功!',{icon:1,time:1000});
					
					
				},
                error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('error!',{icon:1,time:1000});
				}
			});
			
		
			var index = parent.layer.getFrameIndex(window.name);
			parent.$('.btn-refresh').click();
			parent.layer.close(index);
		}
	});
});
</script> 
</body>
</html>